#ifndef RTREACTORWIN32MESSAGE_H
#define RTREACTORWIN32MESSAGE_H

#ifndef RT_WIN32
   #error ERROR: only WIN32 supports Win32 Messages!
#endif // RT_WIN32

#include "RtReactorBase.h"


#ifdef RT_ENABLE_CALENDAR_TIMER
  #include "RtTimerQueueCalendar.h"
#endif // RT_ENABLE_CALENDAR_TIMER

class CRtReactorWin32Message : public CRtReactorBase  
{
public:
	CRtReactorWin32Message();
	virtual ~CRtReactorWin32Message();

	// interface IRtReactor
	virtual RtResult Open();

	virtual RtResult NotifyHandler(
		IRtEventHandler *aEh, 
		IRtEventHandler::MASK aMask);

	virtual RtResult RunEventLoop();

	virtual RtResult StopEventLoop();
	
	virtual RtResult Close();

protected:
	virtual RtResult OnHandleRegister(RT_HANDLE aFd, 
		IRtEventHandler::MASK aMask, IRtEventHandler *aEh);
	virtual void OnHandleRemoved(RT_HANDLE aFd);

	static LRESULT CALLBACK Win32SocketWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

	HWND m_hwndNotify;
	UINT m_dwTimerId;

#ifdef RT_ENABLE_CALENDAR_TIMER
	// interface IRtTimerQueue
	virtual RtResult ScheduleTimer(IRtTimerHandler *aTh, 
					  LPVOID aArg,
					  const CRtTimeValue &aInterval,
					  DWORD aCount);

	virtual RtResult CancelTimer(IRtTimerHandler *aTh);

	CRtTimerQueueCalendar m_CalendarTimer;
#endif // RT_ENABLE_CALENDAR_TIMER
};

class CRtReactorWin32AsyncSelect : public CRtReactorWin32Message
{
public:
	CRtReactorWin32AsyncSelect();
	virtual ~CRtReactorWin32AsyncSelect();

protected:
	virtual RtResult OnHandleRegister(RT_HANDLE aFd, 
		IRtEventHandler::MASK aMask, IRtEventHandler *aEh);
	virtual void OnHandleRemoved(RT_HANDLE aFd);

private:
	RtResult DoAsyncSelect_i(RT_HANDLE aFd, IRtEventHandler::MASK aMask);
};

#endif // !RTREACTORWIN32MESSAGE_H
